<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新闻详情</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
        }
        .container {
            width: 80%;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        .title {
            font-size: 24px;
            font-weight: bold;
            color: #333;
            margin-bottom: 10px;
        }
        .author {
            font-size: 14px;
            color: #666;
            margin-bottom: 10px;
        }
        .time {
            font-size: 14px;
            color: #666;
            margin-bottom: 20px;
        }
        .content {
            font-size: 16px;
            color: #333;
            line-height: 1.6;
            margin-bottom: 20px;
        }
        .image {
            width: 300px;
            height: auto;
            margin-bottom: 20px;
        }
    </style>
    <script src="./jquery/jquery3.1.1.js"></script>
    <!-- 引入bootstrap，需要两个，分别是：css，js（js引入的时候先引入jquery） -->
    <script src="./bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="./bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <div class="title" id="title"></div>
    <div class="author" id="author" ></div>
    <div class="time" id="time"></div>
    <img id="img"  class="image">
    <div class="content">
       <p id="content"></p>
    </div>
</div>

<button id="submit" onclick="mybtn()" >联系我们</button>
</body>

</html>

<script>
    window.onload = function(){
        initDate()
    }
    function mybtn(){
        window.location.href="contacts.html"
    }

    function initDate(){
        $.ajax({
            url:"news/getNewsDetail",
            type:"get",
            dataType:"json",
            contentType:"application/x-www-form-urlencoded",

            data:{
                id:window.location.href.split("=")[1]
            },
            success:function(data){
                if(data.code == 200){
                    let news = data.data;
                document.getElementById("title").innerText =news.title;
                document.getElementById("author").innerText = "作者："+news.author;
                document.getElementById("time").innerText = "发布时间："+news.publish_time;
                document.getElementById("content").innerText = news.content;
                document.getElementById("img").src = news.newsimg;
                console.log(news.author);
                    console.log(news.newsimg)

                }
            }
        })

    }





</script>